package com.crm.daoImpl;

import com.crm.dao.BaseDictDao;
import com.crm.pojo.BaseDict;
import com.crm.pojo.Customer;
import com.crm.util.jdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @version : 1.0
 * @auther : hjx
 * @Date : 2021/6/25
 * @Description : 实训
 */
public class BaseDictDaoImpl implements BaseDictDao {

    @Override
    public String[] getBeseIndustry() {
        Connection conn = null;
        String sql = "SELECT dict_item_name FROM base_dict WHERE dict_type_name='客户行业' ";
        PreparedStatement ps = null;
        ResultSet rs = null;
        String[] s = new String[5];
        int i = 0;

        try {
            conn = jdbcUtils.getCon();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                s[i] = rs.getString(1);
                i++;
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            jdbcUtils.close(conn,ps,rs);
        }
        return s;
    }

    @Override
    public int[] getIndustryCount() {
        Connection conn = null;
        String sql = "SELECT cust_industry,COUNT(*) FROM cst_customer c INNER JOIN base_dict b ON c.cust_industry = b.dict_item_name GROUP BY cust_industry";
        PreparedStatement ps = null;
        ResultSet rs = null;
        int[] num = new int[5];
        int i = 0;

        try {
            conn = jdbcUtils.getCon();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                num[i] = rs.getInt(2);
                i++;
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            jdbcUtils.close(conn,ps,rs);
        }
        return num;
    }

    @Override
    public List<BaseDict> getBeseJb() {
        return null;
    }

    @Override
    public List<BaseDict> getBeseHy() {
        return null;
    }

    @Override
    public BaseDict getBase_dict(String id) {
        return null;
    }
}
